const JwtUtil = require('./jwt');

module.exports = (req,res,next)=>{
  let token = req.query.token || req.body.token || req.headers["token"]
  if(!token){
    res.status(401).send('没有token信息')
    return false
  }else{
    let jwt = new JwtUtil(token);
    let result = jwt.verifyToken(); // 如果通过就next，否则就返回登陆信息不正确
    console.log(result)
    if (result == 'err') {
      res.status(401).send('登录已过期,请重新登录');
      return false
    }
    else {
      next();
    }
  }
}
